﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

using BLL;

namespace DBLWebService
{
    /// <summary>
    /// AdminConfigService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class AdminConfigService : System.Web.Services.WebService
    {
        public AdminConfigService() { }
        public MySoapHeader token;

        [WebMethod]
        [SoapHeader("token")]
        public string HelloWorld()
        {
            
            if (token.userName.Equals( "test") && token.passWord.Equals("test"))
            {
                return "hello world";
            }
            else
                throw new ApplicationException("Authentication Failed!");
            //return "nothing_string";
        }
        [WebMethod]
        public DataSet AdminLogin(string username, string password)
        {
            return AdminConfigBLL.AdminLogin(username, password);
        }

        [WebMethod]
        public int DelAdminByID(int id)
        {
            return AdminConfigBLL.DelAdminByID(id);
        }

        [WebMethod]
        public int AddAdmin(string adminusername, string adminpassword, string adminlevel)
        {
            return AdminConfigBLL.AddAdmin(adminusername, adminpassword, adminlevel);
        }

        [WebMethod]
        public int UpdateAdmin(int id,string adminusername,string adminpassword,string adminlevel)
        {
            return AdminConfigBLL.UpdateAdmin(id, adminusername, adminpassword, adminlevel);
        }

        [WebMethod (Description = "当name=空字符串时候，返回所有的admin用户")]
        public DataSet GetAdminByAdminName(string name)
        {
            return AdminConfigBLL.GetAllAdminByAdminName(name);
        }
        [WebMethod]
        public DataSet GetAdminByID(int id)
        {
            return AdminConfigBLL.GetAdminByID(id);
        }

        //以下是对userlevel的操纵
        [WebMethod(Description = "得到所有等级配置信息")]
        public DataSet GetAllUserLevel()
        {
            return ToolBLL.GetAllUserLevel();
        }

        [WebMethod]
        public  DataSet GetUserLevelByID(int id)
        {
            return AdminConfigBLL.GetUserLevelByID(id);
        }

        [WebMethod (Description ="如果传入空字符串是查找全部")]
        public DataSet FindUserLevelByName(string name)
        {
            return AdminConfigBLL.FindUserLevelByName(name);
        }

        [WebMethod]
        public int AddUserLevel(string userlevelname, int piccount, int basemark)
        {
            return AdminConfigBLL.AddUserLevel(userlevelname, piccount, basemark);
        }

        [WebMethod]
        public int UpdateUserLevel(int id, string userlevelname, int piccount, int basemark)
        {
            return AdminConfigBLL.UpdateUserLevel(id, userlevelname, piccount, basemark);
        }
        //[WebMethod(Description = "获得一件放出的号段")]
        //public DataSet GetOpenedPreCode()
        //{
        //    string sqlstr = "select distinct substr(code8,1,4) from b_available8code";
        //    DataSet ds = DbHelperOra.Query(sqlstr);
        //    return ds;
        //}
        //[WebMethod]
        //public int AddOpenCode(string precode,string[] excludePattern)
        //{
        //    return 0;
        //}
        
        //public string[] Code4ExcludePattern(string[] excludePattern)
        //{
        //    string[] ss = new string[] { "11","22" , "33", "44" };
        //    return ss;
        //}
        
    
    }
    public class MySoapHeader : System.Web.Services.Protocols.SoapHeader
    {

        public string userName = string.Empty;
        public string passWord = string.Empty;
    }
}
